﻿<UserControl x:Class="ScrumFactory.Projects.ProjectsList"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             
             xmlns:SF="clr-namespace:ScrumFactory;assembly=ScrumFactory"                          
             xmlns:SF_Comp="clr-namespace:ScrumFactory.Composition;assembly=ScrumFactory.Composition"                             
             
             xmlns:SF_VM="clr-namespace:ScrumFactory.Projects.ViewModel"
             
             xmlns:SF_Helpers="clr-namespace:ScrumFactory.Windows.Helpers;assembly=ScrumFactory.Windows.Helpers"
             
             xmlns:props="clr-namespace:ScrumFactory.Projects.Properties"
             
             mc:Ignorable="d" 
             x:Name="thisView"

             HorizontalAlignment="Stretch"
             

             
             d:DesignHeight="300" d:DesignWidth="300">
    
    <UserControl.InputBindings>
        <KeyBinding Key="F5" Command="{Binding RefreshProjectListCommand}" />
    </UserControl.InputBindings>
    
    <UserControl.Resources>

        <ObjectDataProvider  x:Key="projectFilterList" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="SF_VM:ProjectStatusFilter"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>

        <ObjectDataProvider  x:Key="createDateFilterList" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="SF_VM:ProjectCreateDateFilter"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>


        <DataTemplate x:Key="projectDataTemplate">

            <Grid Width="290" Margin="0,4,0,4" >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="40"/>
                        <ColumnDefinition Width="*" />                        
                </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>                        
                    </Grid.RowDefinitions>
                    <Image
                        Grid.Column="0" Grid.RowSpan="2"                        
                        DataContext="{Binding Status,Converter={StaticResource EnumToShortConverter}, ConverterParameter={x:Type SF:BacklogItemStatus}}"
                        VerticalAlignment="Top"
                        Style="{StaticResource ProjectStatusImage}"/>
                    <Image                    
                        Grid.Column="0" Grid.RowSpan="2"                                                
                        Source="/Images/Toolbar/pause.png" Width="24" Height="24"
                        VerticalAlignment="Center">
                    <Image.Style>
                        <Style>
                            <Setter Property="Image.Visibility" Value="Collapsed"/>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding IsSuspended}" Value="True">
                                    <Setter Property="Image.Visibility" Value="Visible"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Image.Style>
                </Image>
                <DockPanel Grid.Column="1" Grid.Row="0" HorizontalAlignment="Stretch" LastChildFill="True">                                            
                    <TextBlock TextWrapping="Wrap">
                        <Hyperlink 
                            Command="{Binding Model.ShowDetailWindowCommand, ElementName=thisView}"
                            CommandParameter="{Binding .}">
                            <Run Text="{Binding ProjectName}" FontSize="{StaticResource BigFontSize}" />        
                        </Hyperlink>
                    </TextBlock>
                    <TextBlock Text="{Binding ProjectNumber}" HorizontalAlignment="Right" DockPanel.Dock="Right"  Foreground="{StaticResource SubTextBrush}" FontSize="{StaticResource SmallFontSize}" />
                </DockPanel>
                <TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding ClientName}" />
            </Grid>
            
        </DataTemplate>
    </UserControl.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>


        <Grid Grid.Row="0" >
            <Grid.ColumnDefinitions>               
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            
            
            <WrapPanel Orientation="Horizontal" HorizontalAlignment="Stretch" Grid.Column="0">
                <TextBox                
                    MinWidth="205" HorizontalAlignment="Stretch"
                    Text="{Binding SearchFilterText, UpdateSourceTrigger=PropertyChanged}"                
                    Style="{StaticResource SearchTextBox}"
                    ToolTip="{x:Static props:Resources.Search}" />
                
                <Grid Width="210">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock    
                        Grid.Column="0"
                        Style="{StaticResource LabelTextBlock}"
                        Text="{x:Static props:Resources.At}"/>
                    <ComboBox  
                        Grid.Column="1"
                        HorizontalAlignment="Stretch"
                        SelectedItem="{Binding StatusFilter}"                        
                        ItemsSource="{Binding Source={StaticResource projectFilterList}}">
                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding ., Converter={StaticResource LocalizeConverter},ConverterParameter='ScrumFactory.Projects.ProjectsList,ScrumFactory.Projects'}" />
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>
                </Grid>


                <Grid Width="210">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock               
                        Grid.Column="0"
                        Style="{StaticResource LabelTextBlock}"
                        Text="{x:Static props:Resources.From}"/>

                    <ComboBox         
                        Grid.Column="1" HorizontalAlignment="Stretch"
                        SelectedItem="{Binding CreateDateFilter}"                        
                        ItemsSource="{Binding Source={StaticResource createDateFilterList}}">
                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding ., Converter={StaticResource LocalizeConverter},ConverterParameter='ScrumFactory.Projects.ProjectsList,ScrumFactory.Projects'}" />
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>
                    <Grid.Style>                        
                        <Style TargetType="{x:Type Grid}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding StatusFilter}" Value="0">
                                    <Setter Property="Visibility" Value="Collapsed"/>
                                </DataTrigger>                            
                            </Style.Triggers>
                        </Style>
                    </Grid.Style>
                </Grid>
                <CheckBox Grid.Row="3" Grid.ColumnSpan="2" IsChecked="{Binding OnlyMemberProjects}" Content="{x:Static props:Resources.im_envolved}" HorizontalAlignment="Right"/>
            </WrapPanel>
            
            
           
            <Menu Grid.Column="1"  Margin="0,0,20,0">
                <MenuItem Header="{x:Static props:Resources.New_project}" Command="{Binding CreateProjectCommand}" Style="{StaticResource Toolbar_MenuItemStyle}">
                    <MenuItem.Icon>
                        <Image Source="/Images/ToolBar/Add.png" Width="32" Height="32" Stretch="Uniform"/>
                    </MenuItem.Icon>
                </MenuItem>
            </Menu>
        </Grid>
        <ListBox
            x:Name="projectListBox"
            Grid.Row="1"
            
            ItemContainerStyle="{StaticResource HorizontalLineDividedNoSelectionListBoxItem}"
            SF_Helpers:ItemActivation.ActivationMode="Both"            
            SF_Helpers:ItemActivation.TheCommandToRun="{Binding ShowDetailWindowCommand}"                                    
                    
            ItemsSource="{Binding FilteredProjects}" SelectionMode="Single"
            
            Background="Transparent"
            BorderThickness="0"
            HorizontalContentAlignment="Stretch"                                        
            ScrollViewer.HorizontalScrollBarVisibility="Disabled"
            ScrollViewer.VerticalScrollBarVisibility="Auto"
                                    
            ItemTemplate="{StaticResource projectDataTemplate}">

            <ListBox.GroupStyle>
                <GroupStyle>         
                    <GroupStyle.Panel>
                        <ItemsPanelTemplate>
                            <WrapPanel Orientation="Horizontal"/>
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <TextBlock Style="{StaticResource GroupTextBlock}" Margin="10,10,0,10">
                                <TextBlock 
                                    DataContext="{Binding Name, Converter={StaticResource ShortToEnumConverter},  ConverterParameter={x:Type SF:ProjectStatus}}" 
                                    Text="{Binding ., Converter={StaticResource LocalizeConverter}}"/>
                                <TextBlock Text="{Binding ItemCount, StringFormat='{} ({0})'}"/>
                            </TextBlock>                            
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>                    
                </GroupStyle>
            </ListBox.GroupStyle>

        </ListBox>

        <ContentControl Grid.Row="1"                                                
                        Style="{StaticResource LoadingAnimationContent}"/>
            

        <Grid
            Grid.Row="1" MaxWidth="300"
            HorizontalAlignment="Left">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Image Grid.Column="0" Source="/Images/information.png"  Width="16" Height="16" Stretch="Uniform" Margin="3" VerticalAlignment="Top" />
            <TextBlock Grid.Column="1" TextWrapping="Wrap" >
                <TextBlock TextWrapping="Wrap" Text="{x:Static props:Resources.No_projects_were_found}"/><LineBreak/>
                <TextBlock TextWrapping="Wrap" Margin="0,10,0,0" Foreground="{StaticResource SubTextBrush}" Text="{x:Static props:Resources.No_projects_were_found_tip}"/>
            </TextBlock>
            <Grid.Style>
                <Style>
                    <Setter Property="Grid.Visibility" Value="Collapsed"/>
                    <Style.Triggers>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding ElementName=projectListBox, Path=HasItems}" Value="False"/>
                                <Condition Binding="{Binding IsLoadingData}" Value="False"/>
                            </MultiDataTrigger.Conditions>
                            <Setter Property="Grid.Visibility" Value="Visible"/>
                        </MultiDataTrigger>                        
                    </Style.Triggers>
                </Style>
            </Grid.Style>
        </Grid>

    </Grid>
        
        
        
        
  
  
</UserControl>
